package cn.tedu.charging.cost.repository.impl;

import cn.tedu.charging.common.pojo.param.ProgressCostParam;
import cn.tedu.charging.common.pojo.po.ChargingCostRulePO;
import cn.tedu.charging.cost.mapper.CostRuleMapper;
import cn.tedu.charging.cost.repository.CostRepository;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

@Repository
public class CostRepositoryImpl implements CostRepository {
    private CostRuleMapper costRuleMapper;
    @Autowired
    public void setCostRuleMapper(CostRuleMapper costRuleMapper) {
        this.costRuleMapper = costRuleMapper;
    }

    public ChargingCostRulePO getCostRule(ProgressCostParam cost) {
        QueryWrapper<ChargingCostRulePO> queryWrapper = new QueryWrapper<>();
        int hour = LocalDateTime.now().getHour();
        queryWrapper.eq("station_id", cost.getStationId());
        queryWrapper.ge("end_time", hour);
        queryWrapper.lt("start_time", hour);
        return costRuleMapper.selectOne(queryWrapper);
    }
}
